package com.example.demo.controller;

import com.example.demo.config.RestData;
import com.example.demo.entity.CodeView;
import com.example.demo.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class CodeController {

    @Autowired
    private CodeService codeService;

    @RequestMapping(value = "/saveCode", method = RequestMethod.GET)
    public RestData saveCodeGet(CodeView code) {
        int result = codeService.saveCode(code);
        return RestData.success(result);
    }


    @RequestMapping(value = "/saveCode", method = RequestMethod.POST)
    public RestData saveCodePost(@RequestBody CodeView code) {
        int result = codeService.saveCode(code);
        return RestData.success(result);
    }

    @RequestMapping("/queryCode")
    public RestData queryCode(CodeView code) {
        List<CodeView> result = codeService.queryCode(code);
        return RestData.success(result);
    }

    @RequestMapping("/queryList")
    public RestData queryList() {
        List<CodeView> result = codeService.queryList();
        return RestData.success(result);
    }

}
